package part1;

public aspect Counting {
	private int publicMethodCallCount = 0;
	private int privateMethodCallCount = 0;
	private int protectedMethodCallCount = 0;
	private int packagePrivateMethodCallCount = 0;
	private int staticMethodCallCount = 0;
	private int nonStaticMethodCallCount = 0;
	private int totalMethodCallCount = 0;
	
	pointcut publicMethods():
		(call(public * *(..)) && !within(Counting));
	
	after():
		publicMethods()
	{
		publicMethodCallCount++;
	}
	
	pointcut privateMethods():
		(call(private * *(..))) && !within(Counting);
	
	after():
		privateMethods()
	{
		privateMethodCallCount++;
	}
	
	pointcut protectedMethods():
		(call(protected * *(..))) && !within(Counting);
	
	after():
		protectedMethods()
	{
		protectedMethodCallCount++;
	}
	
	pointcut packagePrivateMethods():
		(call(!public !private !protected * *(..))) && !within(Counting);
	
	after():
		packagePrivateMethods()
	{
		packagePrivateMethodCallCount++;
	}
	
	pointcut staticMethods():
		(call(static * *(..))) && !within(Counting);
	
	after():
		staticMethods()
	{
		staticMethodCallCount++;
	}
	
	pointcut nonStaticMethods():
		(call(!static * *(..))) && !within(Counting);
	
	after():
		nonStaticMethods()
	{
		nonStaticMethodCallCount++;
	}
	
	pointcut allMethods():
		(call(* *.*(..))) && !within(Counting);
	
	after():
		allMethods()
	{
		totalMethodCallCount++;
	}
	
	//Prints table of final numbers only at the end of all the pointcuts
	pointcut mainMethodThatCallsProgram():
		execution(public static void Main.main(String[]));
	
	after():
		mainMethodThatCallsProgram()
	{
		System.out.println("Public Method Call Count: " + publicMethodCallCount);
		System.out.println("Private Method Call Count: " + privateMethodCallCount);
		System.out.println("Protected Method Call Count: " + protectedMethodCallCount);
		System.out.println("Package-Private Method Call Count: " + packagePrivateMethodCallCount);
		System.out.println("Static Method Call Count: " + staticMethodCallCount);
		System.out.println("Non-Static Method Call Count: " + nonStaticMethodCallCount);
		System.out.println("Total Method Call Count: " + totalMethodCallCount);
	}
}
